//package com.ycrlkj.android.modulescore.main.activity;
//
//import android.annotation.SuppressLint;
//import android.content.Context;
//import android.os.Bundle;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.AdapterView;
//import android.widget.ArrayAdapter;
//import android.widget.Spinner;
//import androidx.databinding.DataBindingUtil;
//import androidx.fragment.app.Fragment;
//import androidx.fragment.app.FragmentManager;
//import androidx.fragment.app.FragmentTransaction;
//import androidx.lifecycle.ViewModelProvider;
//import com.blankj.utilcode.util.ToastUtils;
//import com.lxj.xpopup.interfaces.OnConfirmListener;
//import com.ycrlkj.android.modulescore.main.R;
//import com.ycrlkj.android.modulescore.main.databinding.FragmentXxAppointmentSaveBinding;
//import com.ycrlkj.android.modulescore.main.viewmodel.XxAppointmentViewModel;
//import com.ycrlkj.android.modulespublic.common.base.MArrayAdapter;
//import com.ycrlkj.android.modulespublic.common.utils.xpopup.XPopupUtil;
//import com.ycrlkj.android.modulespublic.common.widget.titlebar.MTitleBar;
//import dagger.hilt.android.AndroidEntryPoint;
//
//@AndroidEntryPoint
//public class XxAppointmentSaveFragment extends Fragment {
//
//    private FragmentXxAppointmentSaveBinding binding;
//
//    private XxAppointmentAddActivity activity;
//
//    private XxAppointmentViewModel viewModel;
//
//    private Spinner spinnerAppointmentTime;
//
//    public XxAppointmentSaveFragment() {
//    }
//
//    public static XxAppointmentSaveFragment newInstance() {
//        XxAppointmentSaveFragment fragment = new XxAppointmentSaveFragment();
//        return fragment;
//    }
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//
//        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_xx_appointment_save, container, false);
//        activity = (XxAppointmentAddActivity) getActivity();
//        viewModel = new ViewModelProvider(activity, new ViewModelProvider.AndroidViewModelFactory(activity.getApplication())).get(XxAppointmentViewModel.class);
//
//        binding.setViewModel(viewModel);
//
//        initTitleBar();
//
//        initSpinnerSelectDate();
//
//        initBtn();
//
//        return binding.getRoot();
//    }
//
//    @SuppressLint("SimpleDateFormat")
//    public void initSpinnerSelectDate() {
//
//        Context context = binding.getRoot().getContext();
//
//        spinnerAppointmentTime = binding.spinnerAppointmentTime;
//
//        String[] dates = viewModel.getDates().getValue();
//
//        MArrayAdapter<String> adapter = new MArrayAdapter<>(context, android.R.layout.simple_spinner_item, dates);
//        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        spinnerAppointmentTime.setAdapter(adapter);
//
////        // 下拉宽度
////        spinnerAppointmentTime.setDropDownWidth(500);
////        // 下拉水平方向偏移
////        spinnerAppointmentTime.setDropDownHorizontalOffset(50);
////        // 下拉的垂直方向偏移
////        spinnerAppointmentTime.setDropDownVerticalOffset(50);
////        // 下拉背景
////        spinnerAppointmentTime.setPopupBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ic_launcher_background));
////        // 下拉背景
////        spinnerAppointmentTime.setPopupBackgroundResource(R.drawable.ic_launcher_background);
//
//
//        spinnerAppointmentTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
//            @Override
//            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//                viewModel.getXxAppointment().getValue().setAppointmentTime(dates[position]);
//                binding.setViewModel(viewModel);
//            }
//
//            /**
//             * 当选择从此视图中消失时调用的回调方法。例如，当触控激活或适配器变空时，选择可能会消失。
//             * 父项–现在不包含选定项的AdapterView。
//             */
//            @Override
//            public void onNothingSelected(AdapterView<?> parent) {
//
//            }
//        });
//    }
//
//
//    public void initTitleBar() {
//        MTitleBar titleBar = binding.mTitleBar;
//        titleBar.setBtnEvents(new MTitleBar.BtnEvents() {
//            @Override
//            public void setBtnLeftOnClickListener() {
//                FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
//                supportFragmentManager.popBackStackImmediate();
//            }
//
//            @Override
//            public void setBtnRightOnClickListener() {
//            }
//        });
//    }
//
//    public void initBtn(){
//        binding.btnSave.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if("请选择".equals(viewModel.getXxAppointment().getValue().getAppointmentTime())){
//                    ToastUtils.showLong("请选择洗消日期");
//                    return;
//                }
//
//                Integer payType = viewModel.getFreightOrder().getValue().getType();
//
//                if(payType == 1){
//                    XPopupUtil.showModal(activity, "操作确认: 预约", new OnConfirmListener() {
//                        @Override
//                        public void onConfirm() {
//                            //todo
//                            //发出请求完成预约事件
//                            ToastUtils.showLong("预约成功");
//                        }
//                    });
//                }else{
//                    toPay();
//                }
//            }
//        });
//    }
//
//    public void toPay(){
//
//        //todo
//        //查询系统设置, 找到应该支付金额
//        int payAmount = 499;
//
//        FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
//        XxAppointmentPayFragment xxAppointmentPayFragment = XxAppointmentPayFragment.newInstance(payAmount);
//        transaction.replace(R.id.fragment_container, xxAppointmentPayFragment);
//        transaction.addToBackStack(null);
//        transaction.commit();
//    }
//
//}